
from util import mapping
from flask import request, Blueprint, send_file
from services import service_old as service
from services import service_img as img

import os

old_blue = Blueprint('old', __name__)
basedir = os.path.abspath(os.path.dirname(__file__))

# 没用但得留着
@old_blue.route('/user/info', methods=['get'])
def userInfo():
    data = service.userInfo()
    return data

# 返回老年人信息列表
@old_blue.route('/old', methods=['get'])
def getOld():
    data = service.getAll()
    return data


@old_blue.route('/old/<id>', methods=['get'])
def getOldById(id):
    data = service.getById(id)
    return data


@old_blue.route('/old', methods=['post'])
def addOld():
    request_data = request.get_json()  # 格式 {'id': 169, 'name': '逄无敌', 'mobile': '18680343705', 'address': '536', 'email': '54@qq.com', 'gender': '女', 'age': '542'}
    data = service.add(request_data)
    return data


@old_blue.route('/old', methods=['put'])
def UpdateOld():
    request_data = request.get_json()
    print(request_data)
    request_data = mapping.dictToOldDic(request_data)
    data = service.update(request_data)
    return data


@old_blue.route('/old/<ID>', methods=['delete'])
def deleteOld(ID):
    data = service.deleteByID(ID)
    return data

